using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gun炮弹发射 : MonoBehaviour
{
    public Rigidbody2D rocket;
    public float speed = 20f;
    move player;
    rocket smoke;
    Animator anim;
    // Start is called before the first frame update
    void Start()
    {
        player = transform.parent.GetComponent<move>();
        anim = transform.parent.GetComponent<Animator>();
        rocket = Resources.Load<Rigidbody2D>("rocket");
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.J)) 
        {
            anim.SetTrigger("fire");
            Quaternion rocketDir = Quaternion.Euler(0, 0, 0);//炮弹方向根据旋转的角度来看，此时为正方向
            float rocketSpeed = speed;
            if (!player.bFaceRight)
            {
                rocketDir = Quaternion.Euler(0, 0, 180);//此时为为反方向
                rocketSpeed = -speed;
            }
            Rigidbody2D rockerInstance = Instantiate(rocket,transform.position, rocketDir);//生成炮弹
            rockerInstance.velocity = new Vector2(rocketSpeed, 0);
        }
    }
}
